package com.version1_3.service.implement;

import com.util.format.MapToJson;
import com.version1_3.dao.ShareDao;
import com.version1_3.service.ShareService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by kuibu on 16/1/26.
 */
@Service
public class ShareServiceImpl implements ShareService {
    private static final Logger LOGGER = Logger.getLogger(ShareServiceImpl.class);

    @Autowired
    private ShareDao shareDao;

    @Override
    public String doRecordPageReaded(int pageId) {
        MapToJson doRecordPageReadedResult = new MapToJson("doRecordPageReadedResult", shareDao.doRecordPageReaded(pageId));
        return doRecordPageReadedResult.toJsonString();
    }

    @Override
    public Map getUserInviteInfo(int userId) {
        Map inviteInfoMap  = new HashMap<>();
        String inviteCode = shareDao.getUserInviteCode(userId);
        int invitedFriends = shareDao.getUserInvitedFriends(inviteCode);

        inviteInfoMap.put("inviteCode",inviteCode);
        inviteInfoMap.put("invitedFriends",invitedFriends);
        return inviteInfoMap;
    }

    @Override
    public String submitInvite(int userId,String inviteCode) {
        return new MapToJson("result",shareDao.submitInvite(userId,inviteCode)).toJsonString();
    }

    @Override
    public boolean getUserHasInputInviteCode(int userId) {
        return shareDao.getUserHasInputInviteCode(userId);
    }
}
